/*   1:    */ package org.jetbrains.lang.manifest.header;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.text.LevenshteinDistance;
import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.lang.manifest.psi.Header;
import org.jetbrains.lang.manifest.psi.HeaderValuePart;

import java.util.*;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */ 
/*  22:    */ public class HeaderParserRepository
/*  23:    */ {
/*  24:    */   public static HeaderParserRepository getInstance()
/*  25:    */   {
/*  26: 49 */     return (HeaderParserRepository)ServiceManager.getService(HeaderParserRepository.class);
/*  27:    */   }
/*  28:    */   
/*  29: 52 */   private final NotNullLazyValue<Map<String, HeaderParser>> a = new NotNullLazyValue()
/*  30:    */   {
/*  31:    */     @NotNull
/*  32:    */     protected Map<String, HeaderParser> compute()
/*  33:    */     {
/*  34: 56 */       HashMap localHashMap = ContainerUtil.newHashMap();
/*  35: 57 */       for (HeaderParserProvider localHeaderParserProvider : (HeaderParserProvider[])Extensions.getExtensions(HeaderParserProvider.EP_NAME)) {
/*  36: 58 */         localHashMap.putAll(localHeaderParserProvider.getHeaderParsers());
/*  37:    */       }
/*  38: 60 */       HashMap tmp52_51 = localHashMap;
/*  39: 60 */       if (tmp52_51 == null) {
/*  40: 60 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/header/HeaderParserRepository$1", "compute" }));
/*  41:    */       }
/*  42: 60 */       return tmp52_51;
/*  43:    */     }
/*  44:    */   };
/*  45:    */   
/*  46:    */   @Nullable
/*  47:    */   public HeaderParser getHeaderParser(@Nullable String paramString)
/*  48:    */   {
/*  49: 66 */     return (HeaderParser)((Map)this.a.getValue()).get(paramString);
/*  50:    */   }
/*  51:    */   
/*  52:    */   @NotNull
/*  53:    */   public Collection<HeaderNameMatch> getMatches(@NotNull String paramString)
/*  54:    */   {
/*  55: 71 */     if (paramString == null) {
/*  56: 71 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getMatches" }));
/*  57:    */     }
/*  58: 71 */     HeaderParser localHeaderParser = (HeaderParser)((Map)this.a.getValue()).get(paramString);
/*  59: 72 */     if (localHeaderParser != null)
/*  60:    */     {
/*  61: 73 */       List tmp67_64 = ContainerUtil.emptyList();
/*  62: 73 */       if (tmp67_64 == null) {
/*  63: 73 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getMatches" }));
/*  64:    */       }
/*  65: 73 */       return tmp67_64;
/*  66:    */     }
/*  67: 76 */     LevenshteinDistance localLevenshteinDistance = new LevenshteinDistance();
/*  68: 77 */     TreeSet localTreeSet = new TreeSet();
/*  69: 78 */     for (Map.Entry localEntry : ((Map)this.a.getValue()).entrySet())
/*  70:    */     {
/*  71: 79 */       String str = (String)localEntry.getKey();
/*  72: 80 */       int i = localLevenshteinDistance.calculateMetrics(paramString, str);
/*  73: 81 */       localTreeSet.add(new HeaderNameMatch(i, str));
/*  74:    */     }
/*  75: 83 */     TreeSet tmp208_206 = localTreeSet;
/*  76: 83 */     if (tmp208_206 == null) {
/*  77: 83 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getMatches" }));
/*  78:    */     }
/*  79: 83 */     return tmp208_206;
/*  80:    */   }
/*  81:    */   
/*  82:    */   @NotNull
/*  83:    */   public Set<String> getAllHeaderNames()
/*  84:    */   {
/*  85: 88 */     Set tmp15_10 = ((Map)this.a.getValue()).keySet();
/*  86: 88 */     if (tmp15_10 == null) {
/*  87: 88 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getAllHeaderNames" }));
/*  88:    */     }
/*  89: 88 */     return tmp15_10;
/*  90:    */   }
/*  91:    */   
/*  92:    */   @Nullable
/*  93:    */   public Object getConvertedValue(@NotNull Header paramHeader)
/*  94:    */   {
/*  95: 93 */     if (paramHeader == null) {
/*  96: 93 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getConvertedValue" }));
/*  97:    */     }
/*  98: 93 */     HeaderParser localHeaderParser = getHeaderParser(paramHeader.getName());
/*  99: 94 */     return localHeaderParser != null ? localHeaderParser.getConvertedValue(paramHeader) : null;
/* 100:    */   }
/* 101:    */   
/* 102:    */   @NotNull
/* 103:    */   public PsiReference[] getReferences(@NotNull HeaderValuePart paramHeaderValuePart)
/* 104:    */   {
/* 105: 99 */     if (paramHeaderValuePart == null) {
/* 106: 99 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getReferences" }));
/* 107:    */     }
/* 108: 99 */     Header localHeader = (Header)PsiTreeUtil.getParentOfType(paramHeaderValuePart, Header.class);
/* 109:100 */     if (localHeader != null)
/* 110:    */     {
/* 111:101 */       HeaderParser localHeaderParser = getHeaderParser(localHeader.getName());
/* 112:102 */       if (localHeaderParser != null)
/* 113:    */       {
/* 114:103 */         PsiReference[] tmp76_71 = localHeaderParser.getReferences(paramHeaderValuePart);
/* 115:103 */         if (tmp76_71 == null) {
/* 116:103 */           throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getReferences" }));
/* 117:    */         }
/* 118:103 */         return tmp76_71;
/* 119:    */       }
/* 120:    */     }
/* 121:107 */     PsiReference[] tmp114_111 = PsiReference.EMPTY_ARRAY;
/* 122:107 */     if (tmp114_111 == null) {
/* 123:107 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/header/HeaderParserRepository", "getReferences" }));
/* 124:    */     }
/* 125:107 */     return tmp114_111;
/* 126:    */   }
/* 127:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.lang.manifest.header.HeaderParserRepository

 * JD-Core Version:    0.7.0.1

 */